package com.disability_federation.controller;

import com.disability_federation.mapper.MapperAuditList;
import com.disability_federation.pojo.AuditList;
import com.disability_federation.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.time.LocalDateTime;

/**
 * 职工审核名单操作接口
 */
@RestController
@CrossOrigin
public class ControllerAuditList {

    @Autowired
    private MapperAuditList mapperAuditList;

    /**
     * 查询全部审核名单
     * 默认更新时间升序排序
     */
    @RequestMapping("AL/query")
    public Result query(){
        return Result.success(mapperAuditList.query());
    }

    /**
     * 查询全部审核名单
     * 更新时间降序排序
     */
    @RequestMapping("AL/query/time_desc")
    public Result queryDesc(){
        return Result.success(mapperAuditList.queryDesc());
    }

    /**
     * 查询全部审核名单
     * 姓名升序排序
     */
    @RequestMapping("AL/query/name_asc")
    public Result queryNameAsc(){
        return Result.success(mapperAuditList.queryNameAsc());
    }

    /**
     * 查询全部审核名单
     * 姓名降序排序
     */
    @RequestMapping("AL/query/name_desc")
    public Result queryNameDesc(){
        return Result.success(mapperAuditList.queryNameDesc());
    }

    /**
     * 查询全部审核名单
     * 单位升序排序
     */
    @RequestMapping("AL/query/unit_asc")
    public Result queryUnitAsc(){
        return Result.success(mapperAuditList.queryUnitAsc());
    }

    /**
     * 查询全部审核名单
     * 单位降序排序
     */
    @RequestMapping("AL/query/unit_desc")
    public Result queryUnitDesc(){
        return Result.success(mapperAuditList.queryUnitDesc());
    }

    /**
     * 查询全部审核名单
     * 注册时间升序排序
     */
    @RequestMapping("AL/query/register_time_asc")
    public Result queryRegisterTimeAsc(){
        return Result.success(mapperAuditList.queryRegisterTimeAsc());
    }

    /**
     * 查询全部审核名单
     * 注册时间降序排序
     */
    @RequestMapping("AL/query/register_time_desc")
    public Result queryRegisterTimeDesc(){
        return Result.success(mapperAuditList.queryRegisterTimeDesc());
    }

    /**
     * 查询全部审核名单
     * 上次登入时间升序排序
     */
    @RequestMapping("AL/query/last_login_time_asc")
    public Result queryLastLoginTimeAsc(){
        return Result.success(mapperAuditList.queryLastLoginTimeAsc());
    }

    /**
     * 查询全部审核名单
     * 上次登入时间降序排序
     */
    @RequestMapping("AL/query/last_login_time_desc")
    public Result queryLastLoginTimeDesc(){
        return Result.success(mapperAuditList.queryLastLoginTimeDesc());
    }

    /**
     * 条件查询审核名单
     * 默认更新时间升序排序
     */
    @RequestMapping("AL/query/condition")
    public Result queryCondition(String name, String unit){
        return Result.success(mapperAuditList.queryCondition(name, unit));
    }

    /**
     * 条件查询审核名单
     * 更新时间降序排序
     */
    @RequestMapping("AL/query/condition/time_desc")
    public Result queryConditionDesc(String name, String unit){
        return Result.success(mapperAuditList.queryConditionDesc(name, unit));
    }

    /**
     * 条件查询审核名单
     * 姓名升序排序
     */
    @RequestMapping("AL/query/condition/name_asc")
    public Result queryConditionNameAsc(String name, String unit){
        return Result.success(mapperAuditList.queryConditionNameAsc(name, unit));
    }

    /**
     * 条件查询审核名单
     * 姓名降序排序
     */
    @RequestMapping("AL/query/condition/name_desc")
    public Result queryConditionNameDesc(String name, String unit){
        return Result.success(mapperAuditList.queryConditionNameDesc(name, unit));
    }

    /**
     * 条件查询审核名单
     * 单位升序排序
     */
    @RequestMapping("AL/query/condition/unit_asc")
    public Result queryConditionUnitAsc(String name, String unit){
        return Result.success(mapperAuditList.queryConditionUnitAsc(name, unit));
    }

    /**
     * 条件查询审核名单
     * 单位降序排序
     */
    @RequestMapping("AL/query/condition/unit_desc")
    public Result queryConditionUnitDesc(String name, String unit){
        return Result.success(mapperAuditList.queryConditionUnitDesc(name, unit));
    }

    /**
     * 条件查询审核名单
     * 注册时间升序排序
     */
    @RequestMapping("AL/query/condition/register_time_asc")
    public Result queryConditionRegisterTimeAsc(String name, String unit){
        return Result.success(mapperAuditList.queryConditionRegisterTimeAsc(name, unit));
    }

    /**
     * 条件查询审核名单
     * 注册时间降序排序
     */
    @RequestMapping("AL/query/condition/register_time_desc")
    public Result queryConditionRegisterTimeDesc(String name, String unit){
        return Result.success(mapperAuditList.queryConditionRegisterTimeDesc(name, unit));
    }

    /**
     * 条件查询审核名单
     * 上次登入时间升序排序
     */
    @RequestMapping("AL/query/condition/last_login_time_asc")
    public Result queryConditionLastLoginTimeAsc(String name, String unit){
        return Result.success(mapperAuditList.queryConditionLastLoginTimeAsc(name, unit));
    }

    /**
     * 条件查询审核名单
     * 上次登入时间降序排序
     */
    @RequestMapping("AL/query/condition/last_login_time_desc")
    public Result queryConditionLastLoginTimeDesc(String name, String unit){
        return Result.success(mapperAuditList.queryConditionLastLoginTimeDesc(name, unit));
    }

    /**
     * 审核名单添加
     */
    @RequestMapping("AL/add")
    public Result add(@RequestParam String username, String name, Integer gender, @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate birthday, String phone, String email, String password){
        AuditList auditList = new AuditList();
        auditList.setUsername(username);
        auditList.setName(name);
        auditList.setGender(gender);
        auditList.setBirthday(birthday);
        auditList.setPhone(phone);
        auditList.setEmail(email);
        auditList.setPassword(password);
        auditList.setRegisterTime(LocalDateTime.now());
        auditList.setUpdateTime(LocalDateTime.now());
        if(mapperAuditList.add(auditList)!=null){
            return Result.success(null);
        }
        else{
            return Result.fail();
        }
    }

    /**
     * 审核名单删除
     */
    @RequestMapping("AL/delete")
    //如果为路径传参，使用@PathVariable
    //如果为参数传参，使用@RequestParam
    public Result delete(@RequestParam Integer id){
        if(mapperAuditList.delete(id)!=null){
            return Result.success(null);
        }
        else{
            return Result.fail();
        }
    }

    /**
     * 审核名单批量删除
     */
    @RequestMapping("AL/delete/batch")
    public Result deleteBatch(@RequestParam Integer[] ids){
        if(mapperAuditList.deleteBatch(ids)!=null){
            return Result.success(null);
        }
        else{
            return Result.fail();
        }
    }

    /**
     * 审核名单修改
     */
    @RequestMapping("AL/update")
    public Result update(@RequestBody AuditList auditList){
        if(mapperAuditList.update(auditList)!=null){
            return Result.success(null);
        }
        else{
            return Result.fail();
        }
    }

}